package com.synergy.stockflow.production.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.synergy.stockflow.production.create.MaterialRequisitionVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.synergy.stockflow.production.entity.MaterialRequisition;
import com.synergy.stockflow.production.mapper.MaterialRequisitionMapper;
import com.synergy.stockflow.production.service.MaterialRequisitionService;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class MaterialRequisitionServiceImpl extends ServiceImpl<MaterialRequisitionMapper, MaterialRequisition> implements MaterialRequisitionService{


    @Override
    public List<MaterialRequisitionVo> selectAll(Page<MaterialRequisitionVo> objectPage, @Param("requisitionCode")String requisitionCode,
                                                 @Param("requisitionName")String requisitionName,
                                                 @Param("requiredTime")String requiredTime,
                                                 @Param("status")Integer status){
        return baseMapper.selectAll(objectPage,requisitionCode,requisitionName,requiredTime,status);
    }

    @Override
    public MaterialRequisitionVo selectByCode(String requisitionCode){
        return baseMapper.selectByCode(requisitionCode);
    }

    @Override
    public int updateListStatus(String requisitionId) {
        baseMapper.updateListStatus(requisitionId);
        return 0;
    }

    @Override
    public int countCurrentMonthPlans() {
        QueryWrapper<MaterialRequisition> wrapper = new QueryWrapper<>();
        wrapper.apply("DATE_FORMAT(create_time, '%Y%m') = DATE_FORMAT(CURDATE(), '%Y%m')");
        return (int) this.count(wrapper);
    }


}
